#include"led.h"



void led_init(void)
{
    //配置时钟
    RCC->APB2ENR |=RCC_APB2ENR_IOPAEN;
    //led模式配置
    GPIOA->CRL &=~GPIO_CRL_CNF0;
    GPIOA->CRL |=GPIO_CRL_MODE0;
    GPIOA->CRL &=~GPIO_CRL_CNF1;
    GPIOA->CRL |=GPIO_CRL_MODE1;
    GPIOA->CRH &=~GPIO_CRH_CNF8;
    GPIOA->CRH |=GPIO_CRH_MODE8;



    GPIOA->ODR |=GPIO_ODR_ODR0;
    GPIOA->ODR |=GPIO_ODR_ODR1;
    GPIOA->ODR |=GPIO_ODR_ODR8;
    
}
void led_on(uint16_t led)
{
    GPIOA->ODR &=~led;
}
void led_off(uint16_t led)
{
    GPIOA->ODR |= led;
}

void led_alloff(void)
{
    GPIOA->ODR |= LED1;
    GPIOA->ODR |= LED2;
    GPIOA->ODR |= LED3;
}

void led_tegger(uint16_t led)
{
    if((GPIOA->IDR & led)==0)                      //接收到寄存器的状态
    {
        led_off(led);
    }
    else{
        led_on(led);
    }
}

void sport_led(uint16_t lled[])
{
    while(1)
    {
        int a;
        for( a=0;a<3;a++)
        {
            led_on(lled[a]);
            Delay_ms(500);
            led_off(lled[a]);
        }
    }
}
